package com.alm.web.controller.alm.devexception;

import com.alm.common.core.controller.BaseController;
import com.alm.common.core.domain.AjaxResult;
import com.alm.common.core.page.TableDataInfo;
import com.alm.handle.core.domain.entity.AlmDevException;
import com.alm.handle.core.domain.entity.rq.DevExEditRq;
import com.alm.handle.core.domain.entity.rq.DevExQueryRq;
import com.alm.handle.core.domain.entity.vo.DevExVo;
import com.alm.handle.service.ISysDevExceptionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备异常信息管理前端控制器
 *
 * @author 詹泽峰
 * @date 2024/07/30 15:35
 */
@RestController
@RequestMapping("/alm/dev_ex")
public class AlmDevExController extends BaseController {
    @Resource
    private ISysDevExceptionService sysDevExceptionService;

    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("/list")
    public AjaxResult getDevExList() {
        return sysDevExceptionService.getDevExList();
    }

    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("/get")
    public AjaxResult getDevExNotViewedByMac(@RequestBody DevExQueryRq rq) {
        return sysDevExceptionService.getDevExNotViewedByMac(rq);
    }

    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("/getListByRq")
    public TableDataInfo getExListByRq(@RequestBody DevExQueryRq rq) {
        List<AlmDevException> almDevExceptionListList = sysDevExceptionService.getListByRq(rq);
        return getDataTable(almDevExceptionListList);
    }

    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("/viewed")
    public AjaxResult changeDevExIsViewed(DevExEditRq rq) {
        int row = sysDevExceptionService.updateDevExIsViewed(rq);
        return row > 0 ? AjaxResult.success("异常信息已读") : AjaxResult.error("修改状态失败");
    }
}
